﻿namespace CodeContrib
{
	public class RandomEmailAddress : IRandom<string>
	{
		private readonly RandomFirstName _randomFirstName;
		private readonly RandomLastName _randomLastName;
		private readonly RandomTopLevelDomain _randomTopLevelDomain;
		private readonly RandomWord _randomWord;

		public RandomEmailAddress()
		{
			_randomWord = new RandomWord();
			_randomFirstName = new RandomFirstName();
			_randomLastName = new RandomLastName();
			_randomTopLevelDomain = new RandomTopLevelDomain();
		}

		public string Next()
		{
			var fullName = string.Format("{0}.{1}", _randomFirstName.Next(), _randomLastName.Next());

			return string.Format("{0}@{1}.{2}", fullName, _randomWord.Next(), _randomTopLevelDomain.Next()).ToLower();
		}
	}
}